/**
 * Created by Administrator on 2017/5/27 0027.
 */



$(function () {

    /*移入添加二级导航*/
    $(".all_kind>dl").on({
        "mouseenter":function () {
                var that = this;

                $.getJSON({
                    url: "json/indexdata.json",
                    success: function (res) {
                        var indexDl = $(that).index();
                        var oDiv = $("<dd class='sub-nav'></dd>");//创建dd
                        var oDivheader = $("<div class='sub-nav-header'><div>");//创建头部
                        oDivheader.html("<p>"+ res[indexDl].first[0]+"</p>");    //添加头部标题
                        for( var i = 1; i < res[indexDl].first.length; i++ ){
                            var oDivHeaderA = $('<a href="javascript:;"></a>');     //创建 a 标签
                            var oDivHeaderAImg = $('<div class="sub-nav-header-img"></div>');   //创建div存放图片
                            oDivHeaderAImg.css("backgroundImage","url("+ res[indexDl].first[i] +")");
                            oDivHeaderA.append(oDivHeaderAImg); //div添加到a标签
                            oDivheader.append( oDivHeaderA );   //a标签添加到dd中
                        }

                        var oDivMain = $('<div class="sub-nav-main"></div>');   //创建主体部分
                        //主体右半部分
                        var oDivMainR = $('<div class="sub-nav-right"></div>');
                        oDivMainR.html('<a href="javascript:;" style="background-image:url('+res[indexDl].second[0]+') ;"></a>');

                        //主体左半部分
                        var oDivMainL = $('<div class="sub-nav-left"></div>');
                        for( var k in res[indexDl] ){
                            if ( k !="first" && k!= "second" ){
                                var oDivMainLSon = $(' <div class="sub-nav-left-1"></div>');
                                //console.log(res[indexDl]);
                                 oDivMainLSon.html("<p class='sub-nav-left-title'>"+ res[indexDl][k][0] +"</p>");
                                var oDivMainLSonDiv = $('<div></div>');
                                for( var i = 1; i < res[indexDl][k].length; i++ ){
                                    oDivMainLSonDiv.html( oDivMainLSonDiv.html() + "<a>"+ res[indexDl][k][i] +"</a>" )
                                }
                                oDivMainLSon.append(oDivMainLSonDiv);
                                oDivMainL.append(oDivMainLSon);
                            }
                        }
                        oDivMain.append(oDivMainR);
                        oDivMain.append(oDivMainL);
                        oDiv.append(oDivheader);    //dd添加子元素  头部
                        oDiv.append(oDivMain);    //dd添加子元素  主体内容
                        $(that).append(oDiv);
                    }
                });
        },"mouseleave":function () {
            $(this).children("dd").eq(1).remove();
        }
    });


    /*侧边栏点击特效*/
    /*简单移入特效*/
    $(".sidebar_coupon").on({
        mouseenter: function () {
            $(this).children("div").css("display", "block");
        },
        mouseleave: function () {
            $(this).children("div").css("display", "none");
        }
    });

    $(".sidebar_collect").on({
        mouseenter: function () {
            $(this).children("div").css("display", "block");
        },
        mouseleave: function () {
            $(this).children("div").css("display", "none");
        }
    });

    /*回到顶部按钮*/
    $(document).on("scroll",function () {
        goTop()
    });








    function goTop() {
        var scrollHihg = document.documentElement.clientHeight; //浏览器高度
        var scrollH = $(document).scrollTop();	//隐藏部分高度
        if (scrollH>scrollHihg){
            $(".gotop").fadeIn(1000);
        }else {
            $(".gotop").fadeOut(1000);
        }
    }
    goTop();









});